package com.accountant.travelaccountant;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.GridLayout.LayoutParams;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class EditAccount2_GridView_Adapter extends BaseAdapter {

	EditAccount2 editAccount2;

	Activity activity = new Activity();
	/* String array for string the names of all the buttons */
	String listOfTextViewNames[] = { "Add a new member", "Change the expenses",
			"Rename the above member", "Delete the above member" };
	Integer listOfIds[] = { R.id.textViewAddMemberForEditAccount2,
			R.id.textViewEditPurposeForEditAccount2,
			R.id.textViewRenameForEditAccount2,
			R.id.textViewDeleteForEditAccount2 };
	Context context;

	public EditAccount2_GridView_Adapter(Context context,
			EditAccount2 editAccount2) {
		this.context = context;
		this.editAccount2 = editAccount2;
	}

	@Override
	public int getCount() {
		return listOfTextViewNames.length;
	}

	@Override
	public Object getItem(int arg0) {
		return listOfTextViewNames[arg0];
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView textView = new TextView(context);
		textView.setText(listOfTextViewNames[position]);
		textView.setBackgroundColor(editAccount2.getResources().getColor(
				R.color.Button_Color_Background));
		textView.setTextColor(editAccount2.getResources().getColor(
				R.color.Button_Color_Text));
		textView.setGravity(Gravity.CENTER);
		textView.setLayoutParams(new GridView.LayoutParams(
				LayoutParams.MATCH_PARENT, 50));
		textView.setId(listOfIds[position]);

		textView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.textViewAddMemberForEditAccount2:
					editAccount2.addMember();
					break;
				case R.id.textViewEditPurposeForEditAccount2:
					editAccount2.editPurpose();
					break;
				case R.id.textViewRenameForEditAccount2:
					editAccount2.rename();
					break;
				case R.id.textViewDeleteForEditAccount2:
					editAccount2.deleteMember();
					break;
				default:
					break;
				}
			}
		});

		return textView;
	}

}
